package com.haust.leyou.controller;

import com.haust.leyou.service.SearchService;
import com.haust.leyou.vo.SearchRequest;
import com.haust.leyou.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * @Auther: csp1999
 * @Date: 2020/12/13/18:18
 * @Description:
 */
@Controller
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 商品搜索(附带分页)
     *
     * @param searchRequest
     * @return
     */
    @PostMapping("/page")
    public ResponseEntity<SearchResult> search(@RequestBody SearchRequest searchRequest) {

        SearchResult result = this.searchService.search(searchRequest);
        if (result == null) {
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }
        return ResponseEntity.ok(result);
    }
}
